package com.hotel.service.impl;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hotel.entity.DishCollectLike;
import com.hotel.mapper.DishCollectLikeMapper;
import com.hotel.service.DishCollectLikeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 * 商品点赞和收藏表 服务实现类
 * </p>
 *
 * @author Lin
 * @since 2022-06-08
 */
@Service
public class DishCollectLikeServiceImp extends ServiceImpl<DishCollectLikeMapper, DishCollectLike> implements DishCollectLikeService {


    @Resource
    private DishCollectLikeMapper mapper;


    @Override
    public IPage<DishCollectLike> getCollect(String username, Integer current, Integer size) {
        if (StringUtils.isNotEmpty(username)) {
            username=username.trim();
        }
        List<DishCollectLike> collect = mapper.getCollect(username);
        List pageList = new ArrayList<>();
        int curIdx = current > 1 ? (current - 1) * size : 0;
        for (int i = 0; i < size && curIdx + i < collect.size(); i++) {
            pageList.add(collect.get(curIdx + i));
        }
        IPage page = new Page<>(current, size);
        page.setRecords(pageList);
        page.setTotal(collect.size());
        return page;
    }
}
